package logic

import (
	"context"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/svc"
	"homepage_srv/model"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodSukListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodSukListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodSukListLogic {
	return &GoodSukListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品的规格查询
func (l *GoodSukListLogic) GoodSukList(in *homepage.GoodSukListRequest) (*homepage.GoodSukListResponse, error) {
	var sku model.GoodSku
	sku.GoodId = uint32(in.GoodId)
	goodSKU, err := sku.GoodSKU(uint64(in.GoodId))
	if err != nil {
		pkg.Error("查找失败", zap.Error(err))
		return nil, err
	}
	var list []*homepage.GoodSukList
	for _, h := range goodSKU {
		list = append(list, &homepage.GoodSukList{
			GoodId: int64(h.GoodId),
			Color:  h.Color,
			Stock:  int64(h.Stock),
			Sales:  int64(h.Sales),
			Price:  h.Price,
			Image:  h.Image,
		})
	}
	return &homepage.GoodSukListResponse{
		List: list,
	}, nil
}
